//
//  YQOrderDetailsHeaderView.m
//  MuYing
//
//  Created by tbb on 2019/8/1.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "YQOrderDetailsHeaderView.h"
#import "Calculagraph.h"
#import "YQGoodsOrderDetailsModel.h"
@interface  YQOrderDetailsHeaderView ()
@property (nonatomic,strong) Calculagraph *codeTimer;
@end

@implementation YQOrderDetailsHeaderView

- (void)layoutSubviews {
    [super layoutSubviews];
    self.topBgView.backgroundColor = kAPPThemeColor;
    
    self.locationView.backgroundColor = UIColor.whiteColor;
    self.locationView.layer.cornerRadius=15;
    self.locationView.layer.shadowColor=[UIColor blackColor].CGColor;
    self.locationView.layer.shadowOffset=CGSizeMake(0, 0);
    self.locationView.layer.shadowOpacity=0.5;
    self.locationView.layer.shadowRadius=5;
    self.stateLb.text = @"";

}
/*
* 订单状态：101->订单生成，未支付 ；102->下单后未支付用户取消；103->下单后未支付，超时系统取消；
* 201->支付完成，待发货；202->付款未发货，退款取消；301->已发货，未确认收货；302->用户确认收货；303->系统自动确认收货
*/
-(void)setNewsOrderModel:(YQGoodsOrderDetailsModel *)newsOrderModel {
    _newsOrderModel = newsOrderModel;
    self.timeLb.text = @"";
    switch (newsOrderModel.orderStatus) {
        case 101:
            self.stateLb.text = kYQLS(@"等待买家付款");
            break;
        case 102:
        case 103:
        case 202:
            self.stateLb.text = kYQLS(@"交易失败");
            break;
        case 201:
            self.stateLb.text = kYQLS(@"已付款，等待卖家确认");
            break;
        case 301:
            self.stateLb.text = kYQLS(@"卖家已确认、请使用");
            break;
        case 302:
        case 303:
            self.stateLb.text = kYQLS(@"待评价");
            break;
        
        default:
            break;
    }
}

-(void)setOrderDetailsModel:(YQGoodsOrderDetailsModel *)orderDetailsModel {
    _orderDetailsModel = orderDetailsModel;
    
    /*
     self.headerView.stateLb.text = @"确认收货";
     self.headerView.timeLb.text = @"剩余: 05小时57小时";
     self.headerView.nameLb.text = @"李晓冬";
     self.headerView.phoneLb.text = @"17727956732";
     self.headerView.locationLb.text = @"地址 : 广东省深圳市南山区蛇口街道创业一号C栋";
     */
    self.nameLb.text = orderDetailsModel.userName;
    self.phoneLb.text = orderDetailsModel.userPhone;
    self.locationLb.text = orderDetailsModel.userAddress;
    self.timeLb.hidden = YES;
    switch (self.orderDetailsModel.orderStatus) {
        case 101:
            //"等待买家付款";
        {
            self.stateLb.text = kYQLS(@"等待买家付款");
            self.timeLb.text = self.orderDetailsModel.createTime;
        }
            break;
        case 102:
            self.stateLb.text = kYQLS(@"超时用户取消");
            break;
        case 103:
            self.stateLb.text = kYQLS(@"超时系统取消");
            break;
        case 202:
                self.stateLb.text = kYQLS(@"交易失败");
            break;
        case 201:
                self.stateLb.text = kYQLS(@"等待卖家发货");
            break;
            
        case 301:
                //"卖家已发货";
            self.stateLb.text = kYQLS(@"卖家已发货");
            break;
        case 302:
            self.stateLb.text = kYQLS(@"已申请 退款、等待卖家同意");
            break;

        case 303:
            if ([self.orderDetailsModel.comment isEqualToString:@"0"]) {
                self.stateLb.text = kYQLS(@"待评价");
            }else{
                self.stateLb.text = kYQLS(@"已评价");
            }
            break;
            
        default:
            break;
    }
}

#pragma mark -- 积分商城的订单
- (void)setModel:(YQPOrderInfoModel *)model
{
    _model = model;
    if ([model.orderStatus isEqualToString:@"0"]) {
        self.stateLb.text = kYQLS(@"订单待付款");

    }else if ([model.orderStatus isEqualToString:@"1"]) {
        self.stateLb.text = kYQLS(@"买家已付款，等待卖家发货");

    }else if ([model.orderStatus isEqualToString:@"2"]) {
        self.stateLb.text = kYQLS(@"订单已发货");

    }else if ([model.orderStatus isEqualToString:@"3"]) {
        self.stateLb.text = kYQLS(@"订单已完成");

    }else if ([model.orderStatus isEqualToString:@"4"]) {
        self.stateLb.text = kYQLS(@"订单已关闭");

    }
    self.timeLb.text = @"剩余: 05小时57小时";
    self.nameLb.text = model.receiverName;
    self.phoneLb.text = model.receiverPhone;
    self.locationLb.text = [NSString stringWithFormat:@"%@ : %@%@%@",kYQLS(@"地址"),model.receiverProvince,model.receiverCity,model.receiverDetailAddress];
}

- (Calculagraph *)codeTimer {
    if (!_codeTimer) {
        _codeTimer = [[Calculagraph alloc] init];
        [_codeTimer addObserver:self forKeyPath:@"time" options:NSKeyValueObservingOptionNew context:nil];
    }
    return _codeTimer;
}
- (void)dealloc {
    [self.codeTimer removeObserver:self forKeyPath:@"time"];
    self.codeTimer = nil;
}

@end

